﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WpfTestDemo.Core;
using WpfTestDemo.Dal;

namespace WpfTestDemo.Bll
{
    public class TestInfoBll
    {
		private readonly TestInfoDal dal = new TestInfoDal();

		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(TestInfoCore model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 增加一条数据--返回当前数据的ID
		/// </summary>
		public int AddReturnId(TestInfoCore model)
		{
			return dal.AddReturnId(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(TestInfoCore model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{

			return dal.Delete(Id);
		}

		/// <summary>
		/// 批量删除数据 
		/// </summary>
		/// <param name="ids">如："1,2,3,4"</param>
		/// <returns></returns>
		public bool DeleteList(string ids)
		{
			return dal.DeleteList(ids);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public TestInfoCore GetModel(int Id)
		{

			return dal.GetModel(Id);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<TestInfoCore> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<TestInfoCore> DataTableToList(DataTable dt)
		{
			List<TestInfoCore> modelList = new List<TestInfoCore>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				TestInfoCore model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 取数据条数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		/// <param name="pagIndex">当前页</param>
		/// <param name="pagSize">当前数据大小</param>
		/// <param name="operate">排序操作：asc顺序，desc 倒序</param>
		/// <param name="strWhere">查询条件: a.Id in('1','2','3')</param>
		/// <returns>返回DataTable</returns>
		public DataSet GetListByPage(int pagIndex, int pagSize, OperateType operate = OperateType.ASC, string strWhere = "")
		{
			return dal.GetListByPage(pagIndex, pagSize, operate, strWhere);
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		/// <param name="pagIndex">当前页</param>
		/// <param name="pagSize">当前数据大小</param>
		/// <param name="operate">排序操作：asc顺序，desc 倒序</param>
		/// <param name="strWhere">查询条件: a.Id in('1','2','3')</param>
		/// <returns>返回集合</returns>
		public List<TestInfoCore> GetModelListByPage(int pagIndex, int pagSize, OperateType operate = OperateType.ASC, string strWhere = "")
		{
			DataSet ds = GetListByPage(pagIndex, pagSize, operate, strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}
